#include <bits/stdc++.h>

int a[100010], b[100010];
int n, m;

int main(int argc, char **argv)
{
    freopen("allocation.in", "r", stdin);
    freopen("allocation.out", "w", stdout);
    std::cin >> n >> m;
    for (int i = 1; i <= n; i++)
        std::cin >> a[i];
    for (int i = 1; i <= m; i++)
        std::cin >> b[i];
    for (int i = 1; i <= n; i++)
        a[i] = b[a[i]];
    std::sort(a + 1, a + n + 1);

    long long ans = 0;
    int mindex = m;
    for(int i = n ;i >= 1;--i){
        while(mindex > 0 && a[i] < b[mindex]){
            --mindex;
        }
        if(mindex > 0 ) {
            mindex--;
        }else{
            ans += a[i];
        }
    }
    std::cout << ans << std::endl;
    return 0;
}
